import { organizationList, departmentList, purchaseTypeList,
    deliverySiteByOrgList, costCenterList } from "../../components/axios/url";
import http from "../../components/axios/fetch";


const CommonSlectList = {
    data(){
        return{
            organizationList: [], // 购买机构下拉列表
            departmentList: [], // 部门下拉列表
            purchaseTypeList: [], // 购买类型下拉列表
            deliverySiteByOrgList: [], // 交付地点下拉列表
            costCenterList: [], // 成本中心下拉列表
        }
    },
    methods: {
        getOrganizationList() { // 购买机构下拉列表
            try{
                http.post(organizationList, {}).then(res => {
                    this.organizationList = res.data.data.list
                })
            } catch(error){
                this.$notify.error({
                    title: '提示',
                    message: '网络错误',
                });
            }
        },
        getDepartmentList() { // 部门下拉列表
            try{
                http.post(departmentList, {}).then(res => {
                    if(res.data && res.data.resultMess === "success") {
                        this.departmentList = res.data.data.list
                    }
                })
            } catch(error){
                this.$notify.error({
                    title: '提示',
                    message: '网络错误',
                });
            }
        },
        getPurchaseTypeList() { // 购买类型下拉列表
            try{
                http.post(purchaseTypeList, {}).then(res => {
                    if(res.data && res.data.resultMess === "success") {
                        this.purchaseTypeList = res.data.data.list
                    }
                })
            } catch(error){
                this.$notify.error({
                    title: '提示',
                    message: '网络错误',
                });
            }
        },
        getDeliverySiteByOrgList(organizationId) { // 交付地点下拉列表 与购买机构联动
            try{
                http.post(deliverySiteByOrgList, {organizationId}).then(res => {
                    if(res.data && res.data.resultMess === "success") {
                        this.deliverySiteByOrgList = res.data.data.list
                    }
                })
            } catch(error){
                this.$notify.error({
                    title: '提示',
                    message: '网络错误',
                });
            }
        },
        getCostCenterList() { // 成本中心下拉列表
            try{
                http.post(costCenterList, {}).then(res => {
                    if(res.data && res.data.resultMess === "success") {
                        this.costCenterList = res.data.data.list
                    }
                })
            } catch(error){
                this.$notify.error({
                    title: '提示',
                    message: '网络错误',
                });
            }
        },
    }
}

export default CommonSlectList
